package com.atguigu.sparktuning.cache_01

import com.atguigu.sparktuning.bean.CoursePay
import com.atguigu.sparktuning.utils.InitUtil
import org.apache.spark.SparkConf
import org.apache.spark.sql.{DataFrame, Dataset, SparkSession}

/**
  * @Author  Zhongxu.Zhao
  * @ClassName DatasetCacheDemo
  * @Date 2021/12/13 22:46
  * @Desc: TODO
 **/
object DatasetCacheDemo {
  def main(args: Array[String]): Unit = {
      val sparkConf: SparkConf = new SparkConf().setMaster("local").setAppName(this.getClass.getSimpleName)
      val spark: SparkSession = InitUtil.initSparkSession(sparkConf)
      import  spark.implicits._
      val result: Dataset[CoursePay] = spark.sql("select * from sparktuning.course_pay").as[CoursePay]
      result.cache()
      result.foreachPartition((pays:Iterator[CoursePay]) => pays.foreach(a => println(a.orderid)))

      while(true){}
    }




}
